<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%@ include file="/WEB-INF/jspf/common-imports.jspf" %>
<title>관리자 계정 관리 리스트</title>

	<script type="text/javascript">
		function initEventHandler() {
			// 리스트 > 등록버튼
			$("#btn_reg").click(function() {
				$("#cid_area_reg").show();
				$("#cid_area_list").hide();
			});
			// 등록페이지 > 취소
			$("#btn_member_reg_close").click(function() {
				$("#cid_area_reg").hide();
				$("#cid_area_list").show();
			});
			// 등록페이지 > 등록
			$("#btn_member_reg_save").click(function() {
				doSave();
				
			});
			
			// 상세조회 > 닫기
			$("#btn_member_view_close").click(function() {
				$("#cid_area_view").hide();
				$("#cid_area_list").show();
				doList();
				
			});
			
			// 상세조회 > 수정페이지 호출
			$("#btn_member_view_detail").click(function() {
				doDetail($("#cid_member_view_seq").val());
				$("#cid_area_view").hide();
			});
	
			// 수정페이지 > 취소
			$("#btn_member_detail_close").click(function(){
				$("#cid_area_detail").hide();
				$("#cid_area_view").show();
			});
			// 수정페이지 > 수정완료
			$("#btn_member_detail_save").click(function(){
				doUpdate();
			});

		};
		/** 조회 **/
		function doList() {
			$.invokeGET(
				"/rest/ADMIN/list",
				null,
				function(model) {
					var html = "";
					var data = model.MODEL;
					
					if (data.length > 0 ) {
						$("#cid_panel_member_list > tbody").html('');
						for (var i = 0; i < data.length; i++) {
							html = "";
							html += "<tr onclick='javascript:doView(\""+data[i].seq+"\")'>";
							html += "	<th>"+data[i].seq+"</th>";
							html += "	<th>"+data[i].name+"</th>";
							html += "	<th>"+data[i].id+"</th>";
							html += "	<th>"+data[i].pw+"</th>";
							html += "	<th>"+data[i].tel+"</th>";
							
							if (data[i].last_login_dt != null && data[i].last_login_dt != "") {
								html += "	<th>"+data[i].last_login_dt.toDate().format("yyyy-MM-dd","date")+"</th>";
							} else {
								html += "	<th></th>";
							}
							html += "	<th>"+data[i].reg_dt.toDate().format("yyyy-MM-dd","date")+"</th>";
							html += "	<th>"+data[i].level+"</th>";
							html += "</tr>";
							$("#cid_panel_member_list > tbody").append(html);
						}
						
					} else {
						alert("조회 내용 읍음");
					}
				}
			);	
		}
	
		/** 삭제 **/
		function doDelete() {
			
		}
		/** 상세조회 (뷰) **/
		function doView(idx) {
			
			// 리스트를 안보이게 하기
			$("#cid_area_list").hide();
			
			$.invokeGET(
				'/rest/ADMIN/'+idx,
				null,
				function(model) {
					var data = model.MODEL;
					$("#cid_member_view_id").text(data.id);
					$("#cid_member_view_pw").text(data.pw);
					$("#cid_member_view_name").text(data.name);
					$("#cid_member_view_email").text(data.email);
					$("#cid_member_view_tel").text(data.tel);
					$("#cid_member_view_level").text(data.level);
					$("#cid_member_view_last_login_out").text(data.last_login_out);
					$("#cid_member_view_reg_dt").text(data.reg_dt);
					$("#cid_member_view_seq").val(data.seq);
					$("#cid_area_view").show();
				}
			);
		}
		
		/** 상제조회 (수정)**/
		function doDetail(idx) {
			$.invokeGET(
				'/rest/ADMIN/'+idx,
				null,
				function(model) {
					var data = model.MODEL;
					$("#cid_member_detail_frm #id").val(data.id);
					$("#cid_member_detail_frm #pw").val(data.pw);
					$("#cid_member_detail_frm #name").val(data.name);
					$("#cid_member_detail_frm #email").val(data.email);
					$("#cid_member_detail_frm #tel").val(data.tel);
					$("#cid_member_detail_frm #level").val(data.level);
					$("#cid_member_detail_frm #last_login_out").val(data.last_login_out);
					$("#cid_member_detail_frm #reg_dt").val(data.reg_dt);
					$("#cid_member_detail_frm #seq").val (data.seq);
					$("#cid_area_detail").show();
				}
			);
		}
		
		/** 관리자 등록완료 **/
		function doSave() {
 			$.invokePOST(
				'/rest/ADMIN/add',
				$("#cid_member_reg_frm"),
				function(model) {
					if (model.PROCESS_CODE != true) {
						alert("기존에 있는 사용자 입니다");
					} else {
						$("#cid_member_reg_frm").hide();
						$("#cid_area_list").show();
						doList();
					}
					
				}
			); 
		}
		/** 관리자 수정완료 **/
		function doUpdate() {
			$.invokePUT(
				'/rest/ADMIN/' + $("#cid_member_detail_frm #seq").val(),
				$("#cid_member_detail_frm"),
				function(model) {
					if (model.PROCESS_CODE == true) {
						$("#cid_area_detail").hide();
						doView($("#cid_member_detail_frm #seq").val());
						$("#cid_area_detail").hide();
					} else {
						alert(model.PROCESS_MSG);
					}
				},
				function(error) {
					alert(error.PROCESS_MSG);
				}
			);
		}
		
		$(document).ready(function () {
			doList();
			initEventHandler();
		});
		
	</script>
	
	<!-- ======================== -->
	<style>
		tr:hover {
			background-color:#e1eafe;
			cursor: pointer;
		}
	</style>
</head>
<body>
	<form id="emptyFrm" name="emptyFrm"></form>
	<!-- =============================================== menu 시작 -->
	<%@ include file="/WEB-INF/jspf/menu_header-imports.jsp" %>
	<%@ include file="/WEB-INF/jspf/menu_left-imports.jsp" %>
	<!-- =============================================== menu 끝 -->

	<!-- =============================================== content 시작 -->
	<!-- 리스트 시작 -->
	<div id="cid_area_list">
		<form id="cid_member_list_frm" name="cid_member_list_frm">
		<!-- 버튼 시작 -->
		<div style="text-align:right">
			<a class="btn btn-small btn-primary" id="btn_reg" href="#">
				<i class="icon-plus"></i>
				등록
			</a>
			<a class="btn btn-small btn-primary" id="btn_del" href="javascript:alert('구현중')">
				<i class="icon-minus"></i>
				삭제
			</a>
		</div>
		<br/>
		<!-- 버튼 끝 -->
		<table class="table table-striped table-bordered table-condensed"  id="cid_panel_member_list">
			<thead>
			<tr>
				<th>번호</th>
				<th>이름</th>
				<th>아이디</th>
				<th>비밀번호</th>
				<th>연락처</th>
				<th>최종로그인</th>
				<th>생성일</th>
				<th>권한</th>
			</tr>
			</thead>
			
			<tbody>
			</tbody>
			
			<tfoot>
			</tfoot>
		</table>
		</form>
	</div>	
	<!-- 리스트 끝 -->
	
	<!-- 등록 페이지 시작 -->
	<div id="cid_area_reg" style="display:none" >
		<form id="cid_member_reg_frm" name="cid_member_reg_frm" class="form-inline form-horizontal">
			<fieldset  id="cid_panel_member_reg">
				<legend>관리자 등록</legend>
				<div class="control-group">
					<label class="control-label" for="focusedInput">아이디</label>
					<div class="controls">
						<input class="input-xlarge focused" id="id" name="id" type="text" value="">
            		</div>
          		</div>
				<div class="control-group">
					<label class="control-label" for="focusedInput">비밀번호</label>
					<div class="controls">
						<input class="input-xlarge focused" id="pw" name="pw" type="password" value="">
            		</div>
          		</div>
				<div class="control-group">
					<label class="control-label" for="focusedInput">비밀번호확인</label>
					<div class="controls">
						<input class="input-xlarge focused" id="re_pw" name="re_pw" type="password" value="">
            		</div>
          		</div>
				<div class="control-group">
					<label class="control-label" for="focusedInput">이름</label>
					<div class="controls">
						<input class="input-xlarge focused" id="name" name="name" type="text" value="">
            		</div>
          		</div>
				<div class="control-group">
					<label class="control-label" for="focusedInput">이메일</label>
					<div class="controls">
						<input class="input-xlarge focused" id="email" name="email" type="text" value="">
            		</div>
          		</div>
				<div class="control-group">
					<label class="control-label" for="focusedInput">연락처</label>
					<div class="controls">
						<input class="input-xlarge focused" id="tel" name="tel" type="text" value="">
            		</div>
          		</div>
				<div class="control-group">
					<label class="control-label" for="focusedInput">권한</label>
					<div class="controls">
						<select id="level" name="level">
							<option value="A">관리자</option>
							<option value="E">직원</option>
						</select>
						
            		</div>
          		</div>
				
				<div class="form-actions">
					<a class="btn btn-small btn-primary" id="btn_member_reg_close" href="#">취소</a>
					<a class="btn btn-small btn-primary" id="btn_member_reg_save" href="#">등록</a>
				</div>
				
        	</fieldset>		
		</form>
	</div>
	<!-- 등록 페이지 끝 -->
	
	<!-- 상세 페이지 시작 -->
	<div id="cid_area_view"  style="display:none">
		<form id="cid_member_view_frm" name="cid_member_view_frm">
		<table width="100%" border="1" cellpadding="0" cellspacing="0"
		 		id="cid_panel_member_view">
			<tbody>
			<tr>
				<th>아이디</th>
				<td id="cid_member_view_id"></td>
			</tr>
			<tr>
				<th>비밀번호</th>
				<td id="cid_member_view_pw"></td>
			</tr>
			<tr>
				<th>이름</th>
				<td id="cid_member_view_name"></td>
			</tr>
			<tr>
				<th>이메일</th>
				<td id="cid_member_view_email"></td>
			</tr>
			<tr>
				<th>연락처</th>
				<td id="cid_member_view_tel"></td>
			</tr>
			<tr>
				<th>권한</th>
				<td id="cid_member_view_level"></td>
			</tr>
			<tr>
				<th>최종로그인</th>
				<td id="cid_member_view_last_login_out"></td>
			</tr>
			<tr>
				<th>가입일</th>
				<td id="cid_member_view_reg_dt"></td>
			</tr>
			
			</tbody>
			<tfoot>
				<tr>
					<td colspan="2" align="center">
						<a href="#" id="btn_member_view_close">[닫기]</a>
						<a href="#" id="btn_member_view_detail" >[수정]</a>
					</td>
				</tr>
			</tfoot>
		</table>
		
		<input type="hidden" name="cid_member_view_seq" id="cid_member_view_seq" value=""/>
		</form>
	</div>	
	<!-- 상세 페이지 끝 -->
	
	
	<!-- 수정 페이지 시작 -->
	<div id="cid_area_detail"  style="display:none">
		<form id="cid_member_detail_frm" name="cid_member_detail_frm">
		<table width="100%" border="1" cellpadding="0" cellspacing="0"
				 id="cid_panel_member_detail">
			<tbody>
			<tr>
				<th>아이디</th>
				<td><input type="text" name="id" id="id" value="" readonly="readonly" border="0"/></td>
			</tr>
			<tr>
				<th>비밀번호</th>
				<td><input type="password" name="pw" id="pw" value=""/></td>
			</tr>
			<tr>
				<th>비밀번호확인</th>
				<td><input type="password" name="re_pw" id="re_pw" value=""/></td>
			</tr>
			<tr>
				<th>이름</th>
				<td><input type="text" name="name" id="name" value=""/></td>
			</tr>
			<tr>
				<th>이메일</th>
				<td><input type="text" name="email" id="email" value=""/></td>
			</tr>
			<tr>
				<th>연락처</th>
				<td><input type="text" name="tel" id="tel" value=""/></td>
			</tr>
	
			<tr>
				<th>권한</th>
				<td>
					<select id="level" name="level">
						<option value="A">관리자</option>
						<option value="E">직원</option>
					</select>
				</td>
			</tr>
			</tbody>
			<tfoot>
				<tr>
					<td colspan="2" align="center">
						<a href="#" id="btn_member_detail_close">[취소]</a>
						<a href="#" id="btn_member_detail_save">[수정완료]</a>
					</td>
				</tr>
			</tfoot>
		</table>
		<input type="hidden" name="seq" id="seq" value=""/>
		</form>	
	</div>
	<!-- 수정 페이지 끝 -->
	<!-- =============================================== content 끝 -->
	<!-- =============================================== footer 시작 -->
	<%@ include file="/WEB-INF/jspf/menu_foot-imports.jsp" %>
	<!-- =============================================== footer 끝 -->	
</body>
</html>